package com.baige.api.app.controller;

import com.baige.api.app.sdk.request.UserLikeDeleteRequest;
import com.baige.api.app.sdk.request.UserLikeListRequest;
import com.baige.api.app.sdk.request.UserLikeRequest;
import com.baige.api.app.sdk.response.GoodsResponse;
import com.baige.common.core.BaseResponse;
import com.baige.common.core.MsgResponse;
import com.baige.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户收藏接口
 * @author wulg
 * @date 2018/12/13.
 */
@Api(value = "UserLikeController", description = "用户收藏接口", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/api/rest/user/like")
public class UserLikeController
{
    private static final Logger logger = LoggerFactory.getLogger(UserLikeController.class);


    /**
     * 用户收藏列表
     *
     * @param userId        用户id
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<List<GoodsResponse>>
     */
    @GetMapping(value = "/v1/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户收藏列表", notes = "用户收藏列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<GoodsResponse>> getUserLikeGoodsList(@PathVariable("userId") String userId, @ModelAttribute @Valid UserLikeListRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("用户收藏列表参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 新增用户收藏
     *
     * @param userId          用户id
     * @param requestParams   请求参数
     * @param bindingResult   参数校验
     * @return Result<MsgResponse>
     */
    @PostMapping(value = "/v1/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户收藏", notes = "用户收藏", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> addUserLikeProduct(@PathVariable("userId") String userId, @Valid @RequestBody UserLikeRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("用户收藏参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 删除用户收藏
     *
     * @param userId          用户id
     * @param requestParams   请求参数
     * @param bindingResult   参数校验
     * @return Result<MsgResponse>
     */
    @DeleteMapping(value = "/v1/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "删除用户收藏", notes = "删除用户收藏", httpMethod = "DELETE", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> removeUserLikeProduct(@PathVariable("userId") String userId, @ModelAttribute @Valid UserLikeDeleteRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("删除用户收藏参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }
}
